﻿using System;
using FreeSql;
using FreeSql.DataAnnotations;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BBCore.Core.Models.BaseModels;
using FluentValidation;
using Magicodes.ExporterAndImporter.Core;

namespace BBCore.Core.Models.Samples
{
    public class HYJ_Master_Table : BaseModel, IMasterTable<int, HYJ_Detail_Table>//, IEditLock
    {
        [Column(IsPrimary = true, IsIdentity = true)]
        public int HEAD_ID { get; set; }
        [NotNull]
        [Display(Name = "JOB_NO")]
        [Required(ErrorMessage = "JOB_NO不可为空")]
        public string? JOB_NO { get; set; }
        [Display(Name = "数量")]
        [Required(ErrorMessage = "数量必须大于0")]
        public int QUANTITY { get; set; }
        [Display(Name = "线别(L)")]
        [Required(ErrorMessage = "线别不可为空")]
        public string? LINE_CODE { get; set; }
        [Display(Name = "需求日期")]
        public DateTime REQ_DATE { get; set; } = DateTime.Now;

        
        //[ImporterHeader(IsIgnore = true)]
        //public bool IsEditing { get; set; }

        //[ImporterHeader(IsIgnore = true)]
        //public string? EditingUser { get; set; } = string.Empty;

        //[ImporterHeader(IsIgnore = true)]
        //public DateTime? EditingTime { get; set; }

        [Navigate(nameof(HYJ_Detail_Table.BODY_ID))]
        public List<HYJ_Detail_Table>? Details { get; set; } = [];
    }
    public class HYJ_Master_Table_Validator : AbstractValidator<HYJ_Master_Table>
    {
        public HYJ_Master_Table_Validator()
        {
            RuleFor(x => x.JOB_NO).NotEmpty();
            RuleFor(x => x.LINE_CODE).NotEmpty();
            RuleFor(x => x.QUANTITY).GreaterThan(0);//数量必须大于0
            RuleForEach(x => x.Details).SetValidator(new HYJ_Detail_Table_Validator());
        }


    }
}
